package com.kfm.base.string;

public class CAB {

    public static void main(String[] args) {
        Person p = new Person("赵文翔", '男', 23, false);
        Person p1 = new Person("翠花", '女', 26, false);

        CAB cab = new CAB();
        boolean result = cab.canMarry(p, p1);
        System.out.println(p.getName() + " 与 " + p1.getName() + (result? " 可以登记结婚" : " 不能登记结婚"));
    }

    public boolean canMarry(Person p1, Person p2){
        if (p1 != null && p2 != null){
            if (p1.getMarry() || p2.getMarry()){
                return false;
            }
            if (p1.getGender() == '男'){
                boolean flag = p2.getGender() == '女' && p1.getAge() >= 22 && p2.getAge() >= 20;
                if (flag){
                    return true;
                }
            } else {
                if (p2.getGender() == '男' && p1.getAge() >= 20 && p2.getAge() >= 22){
                    return true;
                }
            }
        }
        return false;
    }
}
